//
//  NearbyDetailViewController.m
//  Finance
//
//  Created by cheng xiang on 13-7-6.
//  Copyright (c) 2013年 cheng xiang. All rights reserved.
//

#import "NearbyDetailViewController.h"
#import "AppDelegate.h"
#import "AnalysisJson.h"
#import "MultiThreading.h"

@interface NearbyDetailViewController ()

@end

@implementation NearbyDetailViewController
@synthesize proId = _proId;
@synthesize showfocusbtn;
@synthesize banknameLabel = _banknameLabel, subjectLabel = _subjectLabel, titleLabel = _titleLabel, imageView = _imageView, currencyLabel = _currencyLabel, beginTimeLabel = _beginTimeLabel, endTimeLabel = _endTimeLabel, startMoneyLabel = _startMoneyLabel, mgrperiodLabel = _mgrperiodLabel, targetLabel = _targetLabel, ideaLabel = _ideaLabel, attentionsLabel = _attentionsLabel, facevalueLabel = _facevalueLabel, fareLabel = _fareLabel, managerprofileLabel = _managerprofileLabel,typeIdLabel = _typeIdLabel,transType = _transType;
@synthesize scrollView = _scrollView,bgView1 = _bgView1,bgView2 = _bgView2;
@synthesize proidLabel = _proidLabel,isSimulate = _isSimulate,simulateAmount = _simulateAmount,flag = _flag;
@synthesize waitingView = _waitingView, activityView = _activityView;
@synthesize lbideal;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.isSimulate = @"0";
    
    if(self.showfocusbtn != 1)
    {
        UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"添加到关注" style:UIBarButtonItemStyleBordered target:self action:@selector(addItem)];
        [rightItem setBackgroundImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self.navigationItem setRightBarButtonItem:rightItem];
    }
    
    _waitingView = [[UIView alloc] initWithFrame:self.view.bounds];
    _waitingView.backgroundColor = [UIColor lightGrayColor];
    _waitingView.alpha = 0.6;
    
    _activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    _activityView.alpha = 1;
    _activityView.center = _waitingView.center;
    [self.view addSubview:_activityView];
    [self.view addSubview:_waitingView];
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-88)];
    UIColor* bk = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"beij.png"]];
    [_scrollView setBackgroundColor:bk];
    [self.view addSubview:_scrollView];
    
    UIImageView *bgview = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, 330, 51)];
    [bgview setImage:[[UIImage imageNamed:@"searchbar.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
    [_scrollView addSubview:bgview];
    
    _subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 5, 195, 40)];
    _subjectLabel.numberOfLines = 0;
    _subjectLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [_subjectLabel setBackgroundColor:[UIColor clearColor]];
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 90, 40)];
    
    UIImageView *celltextbgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 55, 310, 190)];
    [celltextbgView setImage:[[UIImage imageNamed:@"celltextbg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
    [_scrollView addSubview:celltextbgView];
    
    UIImageView *desView = [[UIImageView alloc] initWithFrame:CGRectMake(159, 58, 1, 175)];
    [desView setImage:[UIImage imageNamed:@"desLine.png"]];
    [_scrollView addSubview:desView];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 70, 25)];
    title.text = @"托管期限";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    //title.textColor = [UIColor brownColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _mgrperiodLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 60, 80, 25)];
    _mgrperiodLabel.textAlignment = NSTextAlignmentRight;
    [_mgrperiodLabel setBackgroundColor:[UIColor clearColor]];
    _mgrperiodLabel.font = [UIFont systemFontOfSize:13];
    
    UIImageView *lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 85, 300, 2)];
    lineImageView.image = [UIImage imageNamed:@"cellLine.png"];
    [_scrollView addSubview:lineImageView];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(165, 60, 70, 25)];
    title.text = @"面值";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _facevalueLabel = [[UILabel alloc] initWithFrame:CGRectMake(235, 60, 75, 25)];
    _facevalueLabel.textAlignment = NSTextAlignmentRight;
    [_facevalueLabel setBackgroundColor:[UIColor clearColor]];
    _facevalueLabel.font = [UIFont systemFontOfSize:13];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(10, 90, 70, 25)];
    title.text = @"币种";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _currencyLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 90, 80, 25)];
    _currencyLabel.textAlignment = NSTextAlignmentRight;
    [_currencyLabel setBackgroundColor:[UIColor clearColor]];
     _currencyLabel.font = [UIFont systemFontOfSize:13];
    
    lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 115, 300, 2)];
    lineImageView.image = [UIImage imageNamed:@"cellLine.png"];
    [_scrollView addSubview:lineImageView];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(165, 90, 70, 25)];
    title.text = @"费用";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _fareLabel = [[UILabel alloc] initWithFrame:CGRectMake(235, 90, 75, 25)];
    _fareLabel.textAlignment = NSTextAlignmentRight;
    [_fareLabel setBackgroundColor:[UIColor clearColor]];
    _fareLabel.font = [UIFont systemFontOfSize:13];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(10, 120, 70, 25)];
    title.text = @"起售金额";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _startMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 120, 80, 25)];
    _startMoneyLabel.textAlignment = NSTextAlignmentRight;
    [_startMoneyLabel setBackgroundColor:[UIColor clearColor]];
     _startMoneyLabel.font = [UIFont systemFontOfSize:13];
    lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 145, 300, 2)];
    lineImageView.image = [UIImage imageNamed:@"cellLine.png"];
    [_scrollView addSubview:lineImageView];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(165, 120, 70, 25)];
    title.text = @"产品代码";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _proidLabel = [[UILabel alloc] initWithFrame:CGRectMake(235, 120, 75, 25)];
    _proidLabel.textAlignment = NSTextAlignmentRight;
    [_proidLabel setBackgroundColor:[UIColor clearColor]];
    _proidLabel.font = [UIFont systemFontOfSize:13];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(10, 150, 70, 25)];
    title.text = @"发行银行";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _banknameLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 150, 80, 25)];
    _banknameLabel.textAlignment = NSTextAlignmentRight;
    [_banknameLabel setBackgroundColor:[UIColor clearColor]];
    [_banknameLabel setFont:[UIFont systemFontOfSize:13]];
    _banknameLabel.font = [UIFont systemFontOfSize:13];
    
    lineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 175, 300, 2)];
    lineImageView.image = [UIImage imageNamed:@"cellLine.png"];
    [_scrollView addSubview:lineImageView];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(165, 150, 80, 25)];
    title.text = @"信息关注次数";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _attentionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(245, 150, 65, 25)];
    _attentionsLabel.textAlignment = NSTextAlignmentRight;
    [_attentionsLabel setBackgroundColor:[UIColor clearColor]];
    _attentionsLabel.font = [UIFont systemFontOfSize:13];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(10, 180, 100, 50)];
    title.text = @"开始销售时间";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.numberOfLines = 0;
    title.lineBreakMode = NSLineBreakByWordWrapping;
    //title.font = [UIFont fontWithName:@"MicrosoftYaHei" size:10];
    //title.textColor = [UIColor colorWithRed:120 green:12 blue:9 alpha:100];
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _beginTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 180, 90, 50)];
    _beginTimeLabel.numberOfLines = 0;
    _beginTimeLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _beginTimeLabel.textAlignment = NSTextAlignmentRight;
    _beginTimeLabel.font = [UIFont systemFontOfSize:13];
    [_beginTimeLabel setBackgroundColor:[UIColor clearColor]];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(165, 180, 100, 50)];
    title.text = @"截止销售时间";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.numberOfLines = 0;
    title.lineBreakMode = NSLineBreakByWordWrapping;
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    _endTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(220, 180, 90, 50)];
    _endTimeLabel.textAlignment = NSTextAlignmentRight;
    _endTimeLabel.numberOfLines = 0;
    _endTimeLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _endTimeLabel.font = [UIFont systemFontOfSize:13];
    [_endTimeLabel setBackgroundColor:[UIColor clearColor]];
    
    celltextbgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 250, 310, 40)];
    [celltextbgView setImage:[[UIImage imageNamed:@"celltextbg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)]];
    [_scrollView addSubview:celltextbgView];
    
    title = [[UILabel alloc] initWithFrame:CGRectMake(10, 260, 60, 20)];
    title.text = @"投资目标";
    title.font = [UIFont systemFontOfSize:13];
    title.backgroundColor = [UIColor clearColor];
    title.numberOfLines = 0;
    title.lineBreakMode = NSLineBreakByWordWrapping;
    title.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    [_scrollView addSubview:title];
    
    _targetLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 260, 230, 20)];
    _targetLabel.textAlignment = NSTextAlignmentRight;
    _targetLabel.font = [UIFont systemFontOfSize:13];
    [_targetLabel setBackgroundColor:[UIColor clearColor]];
    
    
    
    
    
    
    
    
    
    UIImage *textbgImage = [UIImage imageNamed:@"celltextbg.png"];
    _bgView1 = [[UIImageView alloc] initWithFrame:CGRectZero];
    _bgView2 = [[UIImageView alloc] initWithFrame:CGRectZero];
    _bgView3 = [[UIImageView alloc] initWithFrame:CGRectZero];
    
    
    //        _banknameLabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 5, 140, 20)];
    //        [_banknameLabel setBackgroundColor:[UIColor clearColor]];
    //        _targetLabel = [[UILabel alloc] initWithFrame:CGRectMake(165, 30, 120, 20)];
    //        [_targetLabel setBackgroundColor:[UIColor clearColor]];
    //        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 180, 20)];
    //         [_titleLabel setBackgroundColor:[UIColor clearColor]];
    //        _currencyLabel = [[UILabel alloc] initWithFrame:CGRectMake(190, 60, 100, 20)];
    //         [_currencyLabel setBackgroundColor:[UIColor clearColor]];
    //        _beginTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 85, 150, 20)];
    //        [_beginTimeLabel setBackgroundColor:[UIColor clearColor]];
    //        _endTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 85, 150, 20)];
    //         [_endTimeLabel setBackgroundColor:[UIColor clearColor]];
    //        _startMoneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 110, 150, 20)];
    //         [_startMoneyLabel setBackgroundColor:[UIColor clearColor]];
    
    lbideal = [[UILabel alloc] initWithFrame:CGRectMake(10, 302, 80, 20)];
    lbideal.font = [UIFont systemFontOfSize:13];
    [lbideal setBackgroundColor:[UIColor clearColor]];
    lbideal.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    
    _ideaLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [_ideaLabel setBackgroundColor:[UIColor clearColor]];
    _bgView1.image = [textbgImage resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    _ideaLabel.clipsToBounds = NO;
    [_scrollView addSubview:_bgView1];
    _ideaLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _ideaLabel.numberOfLines = 0;
    _ideaLabel.font = [UIFont systemFontOfSize:13];
    //        _attentionsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    //         [_attentionsLabel setBackgroundColor:[UIColor clearColor]];
    //        _typeIdLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    //         [_typeIdLabel setBackgroundColor:[UIColor clearColor]];
    //        _facevalueLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    //         [_facevalueLabel setBackgroundColor:[UIColor clearColor]];
    //        _fareLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    //        [_fareLabel setBackgroundColor:[UIColor clearColor]];
    _managerprofileLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [_managerprofileLabel setBackgroundColor:[UIColor clearColor]];
    _managerprofileLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _managerprofileLabel.numberOfLines = 0;
      _managerprofileLabel.font = [UIFont systemFontOfSize:13];
    _bgView2.image = [textbgImage resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    _managerprofileLabel.clipsToBounds = NO;
    [_scrollView addSubview:_bgView2];
    
    _typeIdLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    [_typeIdLabel setBackgroundColor:[UIColor clearColor]];
    _typeIdLabel.textAlignment = NSTextAlignmentRight;
    _typeIdLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _typeIdLabel.numberOfLines = 0;
     _typeIdLabel.font = [UIFont systemFontOfSize:13];
    _bgView3.image = [textbgImage resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    _typeIdLabel.clipsToBounds = NO;
    [_scrollView addSubview:_bgView3];
    
    _titleLab = [[UILabel alloc] initWithFrame:CGRectZero];
    _titleLab.text = @"产品类型";
    _titleLab.font = [UIFont systemFontOfSize:13];
    _titleLab.backgroundColor = [UIColor clearColor];
    _titleLab.textColor = [UIColor colorWithRed:120.0/255 green:12.0/255 blue:9.0/255 alpha:1];
    _titleLab.numberOfLines = 0;
    _titleLab.lineBreakMode = NSLineBreakByWordWrapping;
    [_scrollView addSubview:_titleLab];
    
    
    [bgview addSubview:_imageView];
    [_scrollView addSubview:_banknameLabel];
    [_scrollView addSubview:_subjectLabel];
    //        [_scrollView addSubview:_titleLabel];
    [_scrollView addSubview:_currencyLabel];
    [_scrollView addSubview:_beginTimeLabel];
    [_scrollView addSubview:_endTimeLabel];
    [_scrollView addSubview:_startMoneyLabel];
    [_scrollView addSubview:_mgrperiodLabel];
    [_scrollView addSubview:_targetLabel];
    [_scrollView addSubview:_ideaLabel];
    [_scrollView addSubview:lbideal];
    [_scrollView addSubview:_attentionsLabel];
    [_scrollView addSubview:_typeIdLabel];
    [_scrollView addSubview:_facevalueLabel];
    [_scrollView addSubview:_fareLabel];
    [_scrollView addSubview:_managerprofileLabel];
    [_scrollView addSubview:_proidLabel];
    
    self.view.backgroundColor = [UIColor whiteColor];

    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(goReturn)];
    [leftItem setBackgroundImage:[UIImage imageNamed:@"btn.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //增加navigationcontroller的toolbar
    UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIButton *resultBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    resultBtn.frame = CGRectMake(0, 7, 105, 30);
    [resultBtn addTarget:self action:@selector(getPre) forControlEvents:UIControlEventTouchUpInside];
    [resultBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [resultBtn setTitle:@"查看发布用户" forState:UIControlStateNormal];
    UIButton *Btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    Btn.frame = CGRectMake(0, 7, 105, 30);
    [Btn addTarget:self action:@selector(clickOnBtn) forControlEvents:UIControlEventTouchUpInside];
    [Btn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [Btn setTitle:@"预约" forState:UIControlStateNormal];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:resultBtn];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithCustomView:Btn];
    [self setToolbarItems:[NSArray arrayWithObjects:spaceItem,item,spaceItem,item2,spaceItem, nil]animated:YES];
    [self.navigationController.toolbar setBarStyle:UIToolbarPositionTop];
    
    [self packageRequest:@"W103"];
    
}

- (void)disappearOwnerView
{
    
}

- (void)clickOnBtn
{
    if (self.proId == nil || [self.proId isEqualToString:@""] ) {
        return;
    }
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (delegate.loginSessionID == nil || [delegate.loginSessionID isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有登录，请登录后再尝试预约" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
        alert.tag = 0;
        [alert show];
    }else{
        [self packageRequest:@"W112"];
    }
}

- (void)getPre
{
    ProductOwnerViewController *aController = [[ProductOwnerViewController alloc] init];
    [aController drawView:self.proDic];
    [self.navigationController pushViewController:aController animated:YES];
}

- (void)viewDidAppear:(BOOL)animated
{
    if (![self.flag isEqualToString:@"MAP"]) {
        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        UITabBarController *aController = (UITabBarController *)delegate.window.rootViewController;
        [delegate hideTabBar:aController];
        
    }
    [self.navigationController setToolbarHidden:NO];
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.toolbarHidden = YES;
    [super viewWillDisappear:animated];
}

- (void)goReturn
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)addItem
{
    if (self.proId == nil || [self.proId isEqualToString:@""] ) {
        return;
    }
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (delegate.loginSessionID == nil || [delegate.loginSessionID isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您还没有登录，请登录后再尝试添加到关注" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
        alert.tag = 0;
        [alert show];
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您是否模拟购买" delegate:self cancelButtonTitle:@"不，谢谢" otherButtonTitles:@"确定模拟购买", nil];
        alert.tag = 1;
        alert.alertViewStyle = UIAlertViewStylePlainTextInput;
        [[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
        [[alert textFieldAtIndex:0] setPlaceholder:@"请输入模拟购买数量"];
        [alert show];
        //[self packageRequest:@"W109"];
    }
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 0) {
        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        UITabBarController *aController = (UITabBarController *)delegate.window.rootViewController;
        [delegate showTabBarWithoutAnimation:aController];
        [self.tabBarController setSelectedIndex:4];
    }else{
        if (buttonIndex == alertView.cancelButtonIndex) {
            self.isSimulate = @"0";
            [self packageRequest:@"W109"];
        }else{
            self.isSimulate = @"1";
            self.simulateAmount = [alertView textFieldAtIndex:0].text;
            if (self.simulateAmount != nil && ![self.simulateAmount isEqualToString:@""])
            {
                [self packageRequest:@"W109"];
            }else{
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"必须填写购买数量后才能确认购买！" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil];
                [alert show];
            }
        }
    }
}

- (void)getDataForId :(NSString *)proId
{
    self.proId = proId;
    [self packageRequest:@"W103"];
}

- (void)drawView :(NSDictionary *)dic
{
    self.proId = [dic objectForKey:@"prodId"];
    [self putTextToView:dic];
}

- (void)controlActivity:(BOOL)animating
{
    if (animating) {
        //显示正在加载画面
        [self.view bringSubviewToFront:_waitingView];
        [self.view bringSubviewToFront:_activityView];
        _waitingView.hidden = NO;
        _activityView.hidden = NO;
        [_activityView startAnimating];
    }else{
        [_activityView stopAnimating];
        [_activityView setHidden:YES];
        [_waitingView setHidden:YES];
        [self.view sendSubviewToBack:_waitingView];
        [self.view sendSubviewToBack:_activityView];
    }
    
}

- (void)packageRequest: (NSString *)transType
{
    [self controlActivity:YES];
    //组请求报文
    self.transType = transType;
    NSString *server = @"";
    NSDictionary *header = [AnalysisJson PackageJsonHeader:transType];
    if ([@"W103" isEqualToString:transType]) {
        server = @"QueryProdDetail";
    }else if([@"W109" isEqualToString:transType]){
        server = @"AddUserAttention";
    }else if([@"W112" isEqualToString:transType]){
        server = @"OrderService";
    }
    NSDictionary *body = [self PackageBody:self.proId];
    NSData *requestJson = [AnalysisJson PackageJsonFromHeader:header andBody:body];
    
    //发送报文
    [self getTableData: requestJson server:server];
}

//每次组报文需要实现类似组body的方法
- (NSDictionary *)PackageBody:(NSString *)proId
{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
    [dic setObject:proId forKey:@"prodId"];
    
    if ([_transType isEqualToString:@"W109"]) {
        AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        if (delegate.loginSessionID == nil || [delegate.loginSessionID isEqualToString:@""]) {
            
        }else{
            [dic setObject:delegate.loginSessionID forKey:@"sessionId"];
        }
        [dic setObject:self.isSimulate forKey:@"isSimulate"];
        if ([self.isSimulate isEqualToString:@"1"]) {
            [dic setObject:self.simulateAmount forKey:@"simulateAmount"];
        }
    }else if([_transType isEqualToString:@"W112"]){
        
    }
    
    return dic;
}

- (void)getTableData:(NSData *)data server:(NSString *)server
{
    [MultiThreading getDataFromNetwork:[SERVICE_URL stringByAppendingString:server] toObject:self callBack:@selector(requestCallBack:) withBody:data];
}

- (void)requestCallBack:(NSDictionary *)dic
{
    [self controlActivity:NO];
    
    NSDictionary *head = [dic objectForKey:@"header"];
    NSString *transType = [head objectForKey:@"transType"];
    if ([transType isEqualToString:@"W109"]) {
        NSString *returnMsg = [head objectForKey:@"returnMessage"];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"添加结果" message:returnMsg delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil];
        [alert show];
    }else if([@"W103" isEqualToString:transType]){
        NSDictionary *detailDic = nil;
        NSObject *body = dic[@"body"];
        if([body isKindOfClass:[NSDictionary class]] && [(NSDictionary *)body objectForKey:@"product"] != nil)
        {
            detailDic = [(NSDictionary *)body objectForKey:@"product"];
        }
        self.proDic = detailDic;
        [self putTextToView:detailDic];
    }
    
}

- (void)drawBankImage:(NSObject *)obj
{
    if ([obj isKindOfClass:[NSString class]]) {
        NSString *imageurl = (NSString *)obj;
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageurl]]];//后面使用这个url的方法
        //UIImage *image = [UIImage imageWithContentsOfFile:imageurl];
        
        [self performSelectorOnMainThread:@selector(setImageViewFrame:) withObject:image waitUntilDone:NO];
    }
}

- (void)setImageViewFrame:(UIImage *)image
{
    _imageView.image = image;
    CGRect imageViewRect = CGRectMake(0, 0, image.size.height > 40 ? 43 : image.size.width, image.size.height > 40 ? 40 : image.size.height);
    CGPoint center = _imageView.center;
    _imageView.frame = imageViewRect;
    _imageView.center = center;
}

- (void)putTextToView:(NSDictionary *)detailDic
{
    [NSThread detachNewThreadSelector:@selector(drawBankImage:) toTarget:self withObject:[detailDic objectForKey:@"imageUrl"]];
    //[dic objectForKey:@"imageUrl"]到时候用这个替换
    //[[NSBundle mainBundle] pathForResource:@"testImage" ofType:@"jpg"]
    _banknameLabel.text = [detailDic objectForKey:@"bankName"];
    _subjectLabel.text = [detailDic objectForKey:@"subject"];
    //    _titleLabel.text = [detailDic objectForKey:@"title"];
    _currencyLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"currency"]];
    
    NSString *beginTime = [detailDic objectForKey:@"beginTime"];
    NSArray *timeArray = [beginTime componentsSeparatedByString:@" "];
    NSString *date = timeArray.count > 0 ? [timeArray objectAtIndex:0] : @"";
    _beginTimeLabel.text = [NSString stringWithFormat:@"%@",date];
    
    NSString *endTime = [detailDic objectForKey:@"endTime"];
    timeArray = [endTime componentsSeparatedByString:@" "];
    date = timeArray.count > 0 ? [timeArray objectAtIndex:0] : @"";
    _endTimeLabel.text = [NSString stringWithFormat:@"%@",date];
    
    
    _startMoneyLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"startMoney"]];
    _mgrperiodLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"mgrPeriod"]];
    _targetLabel.text = [detailDic objectForKey:@"target"];
    lbideal.text = [NSString stringWithFormat:@"%@",@"投资理念:"];
    _ideaLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"idea"]];
    _proidLabel.text = [detailDic objectForKey:@"prodId"];
    //动态更新label高度
    CGSize textSize = [_ideaLabel.text sizeWithFont:_ideaLabel.font constrainedToSize:CGSizeMake(300, 999) lineBreakMode:NSLineBreakByWordWrapping];
    [_ideaLabel setFrame:CGRectMake(20, 315, 280, textSize.height+5)];
    _bgView1.frame = CGRectMake(_ideaLabel.frame.origin.x-15, _ideaLabel.frame.origin.y-15, _ideaLabel.bounds.size.width+30, _ideaLabel.bounds.size.height+30);
    
    _attentionsLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"attentions"]];
    //_attentionsLabel.frame = CGRectMake(10, _ideaLabel.frame.origin.y+_ideaLabel.frame.size.height+25, 150, 20);
    NSString *typeId = [detailDic objectForKey:@"typeId"];
    if ([typeId isEqualToString:@"3"]) {
        _typeIdLabel.text = @"非保本";
    }else if([typeId isEqualToString:@"5"]){
        _typeIdLabel.text = @"保本";
    }else{
        _typeIdLabel.text = @"";
    }
    //_typeIdLabel.frame = CGRectMake(160, _ideaLabel.frame.origin.y+_ideaLabel.frame.size.height+25, 150, 20);
    _facevalueLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"faceValue"]];
    //_facevalueLabel.frame = CGRectMake(10, _ideaLabel.frame.origin.y+_ideaLabel.frame.size.height+50, 150, 20);
    _fareLabel.text = [NSString stringWithFormat:@"%@",[detailDic objectForKey:@"fare"]];
    //_fareLabel.frame = CGRectMake(160, _ideaLabel.frame.origin.y+_ideaLabel.frame.size.height+50, 150, 20);
    _managerprofileLabel.text = [detailDic objectForKey:@"managerProfile"];
    textSize = [_managerprofileLabel.text sizeWithFont:_managerprofileLabel.font constrainedToSize:CGSizeMake(300, 999) lineBreakMode:NSLineBreakByWordWrapping];
    [_managerprofileLabel setFrame:CGRectMake(20, _ideaLabel.frame.origin.y+_ideaLabel.frame.size.height+30, 280, textSize.height)];
    _bgView2.frame = CGRectMake(_managerprofileLabel.frame.origin.x-15, _managerprofileLabel.frame.origin.y-15, _managerprofileLabel.bounds.size.width+30, _managerprofileLabel.bounds.size.height+30);
    
    
    _typeIdLabel.frame = CGRectMake(90, _managerprofileLabel.frame.origin.y+_managerprofileLabel.frame.size.height+30, 210, 20);
    _bgView3.frame = CGRectMake(_typeIdLabel.frame.origin.x-85, _typeIdLabel.frame.origin.y-15, _typeIdLabel.bounds.size.width+100, _typeIdLabel.bounds.size.height+30);
    _titleLab.frame = CGRectMake(20, _managerprofileLabel.frame.origin.y+_managerprofileLabel.frame.size.height+30, 70, 20);
    _scrollView.contentSize = CGSizeMake(320, _typeIdLabel.frame.origin.y+_typeIdLabel.frame.size.height+30);
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
